cd "C:\Users\alen_\Dropbox\burning_glass\data"

clear all

*** Number of workers who work remotely full time 

** Total
u "atus_household.dta", clear

merge m:1 year caseid using "atus_person.dta"
drop _merge

merge 1:m year caseid using "atus_activity.dta"
drop _merge

g college=0
replace college=1 if educ>=40

keep if age>=25 & age<=65
keep if empstat==1

*drop if day==7 | day==1

replace wt06=wt20 if wt06==.

keep if activity==050101

bysort year caseid: egen total_duration=total(duration)
*keep if total_duration>=6
g home=0
replace home=1 if where==101

collapse home (first) wt06, by(year caseid)
g remote=0
replace remote=1 if home==1

collapse remote [w=wt06], by(year)

sort year
g remote0=remote[_n-1]

g remote_true=(remote-0.25*remote0)/0.75 if year==2020

replace remote=remote_true if year==2020

ren remote remote_atus
merge 1:1 year using acs_remote 
drop if _merge==2
drop _merge 

graph twoway (line remote year, lpattern(solid)) (line remote_atus year, lpattern(longdash)), graphregion(color(white)) yscale(range(0 0.6)) ylabel(0(0.1)0.6) xlabel(2005 "2005" 2010 "2010" 2015 "2015" 2020 "2020 Post Q1") xscale(range(2004 2022)) legend(lab(1 "American Community Survey") lab(2 "American Time Use Survey")) ytitle(Share of Workers WFH) xtitle(Year) 
graph export remote_overall.png, replace







*** By occupation group 

clear all
append using "2009_2014.dta"

append using "2019.dta"

append using "2020.dta"

replace multyear=2020 if multyear==.

append using "2021.dta"
replace multyear=2021 if multyear==.
append using "2022.dta"
replace multyear=2022 if multyear==.

keep if age>=25 & age<=65

keep if uhrswork>=20 & uhrswork<90

sort occ2010 multyear

by occ2010 multyear: egen total=total(perwt)

drop if tranwork==0

g remote=0
replace remote=1 if tranwork==80

** Management
g occ2010_group=5 if occ2010>=10 & occ2010<=430  
** Business and financial
replace occ2010_group=6 if occ2010>=500 & occ2010<=950  
*** Computer and mathematical
replace occ2010_group=8 if occ2010>=1000 & occ2010<=1240  
** Architecture and engineering
replace occ2010_group=9 if occ2010>=1300 & occ2010<=1560  
** Life, physical, and social science
replace occ2010_group=10 if occ2010>=1600 & occ2010<=1980  
*** Community and social service
replace occ2010_group=12 if occ2010>=2000 & occ2010<=2060  
** legal
replace occ2010_group=13 if occ2010>=2100 & occ2010<=2150  
** Education, training, and library
replace occ2010_group=14 if occ2010>=2200 & occ2010<=2550  
**Arts, design, entertainment, sports, and media 
replace occ2010_group=15 if occ2010>=2600 & occ2010<=2920  
**Health diagnosing and treating practitioners and other technical 
replace occ2010_group=16 if occ2010>=3000 & occ2010<=3540  
** Health technologists and technicians
replace occ2010_group=20 if occ2010>=3600 & occ2010<=3650  
** Fire fighting and prevention, and other protective service 
replace occ2010_group=21 if occ2010>=3700 & occ2010<=3950  
** Food preparation and serving related
replace occ2010_group=24 if occ2010>=4000 & occ2010<=4150  
** Building and grounds cleaning and maintenance 
replace occ2010_group=25 if occ2010>=4200 & occ2010<=4250  
** Personal care and service
replace occ2010_group=26 if occ2010>=4300 & occ2010<=4650  
** Sales and related
replace occ2010_group=28 if occ2010>=4700 & occ2010<=4965  
** Office and administrative support
replace occ2010_group=29 if occ2010>=5000 & occ2010<=5940  
** Farming, fishing and forestry
replace occ2010_group=31 if occ2010>=6005 & occ2010<=6130  
** Construction and extraction 
replace occ2010_group=32 if occ2010>=6200 & occ2010<=6940  
** Installation, maintenance, and repair 
replace occ2010_group=33 if occ2010>=7000 & occ2010<=7630  
** Production occupations
replace occ2010_group=35 if occ2010>=7700 & occ2010<=8965  
** Transportation occupations
replace occ2010_group=36 if occ2010>=9000 & occ2010<=9420  
** Material moving occupations
replace occ2010_group=37 if occ2010>=9510 & occ2010<=9750
** unemployed
replace occ2010_group=38 if occ2010==9920  


collapse remote total [w=perwt], by(occ2010_group multyear)

replace multyear=2020 if multyear==. 

ren multyear year

sort occ2010_group year 

by occ2010_group: egen remote_mean=total(remote) if year<=2019


foreach num of numlist 5(1)38 {
	sum remote if year==2019 & occ2010_group==`num'
replace remote=(remote-0.25*r(mean))/0.75 if year==2020 & occ2010_group==`num'
}

graph twoway ( line remote year if occ2010_group==6, lpattern(dash)) ( line remote year if occ2010_group==8, lpattern(solid)) ( line remote year if occ2010_group==24, lpattern(longdash)) ( line remote year if occ2010_group==16, lpattern(longdash_dot)), graphregion(color(white)) yscale(range(0 0.6)) ylabel(0(0.1)0.6) xlabel(2005 "2005" 2010 "2010" 2015 "2015" 2020 "2020 Post Q1") xscale(range(2004 2022)) legend(lab(1 "Business and Financial") lab(2 "Computer and Mathematical") lab(3 "Food Prep and Service") lab(4 "Health")) xtitle(Year) ytitle(Share of WFH Workers)
graph export remote_acs_occupation.png, replace

